package com.aso114.project.util;

import com.aso114.project.bean.QuestionBaseBean;
import com.aso114.project.bean.QuestionBean;
import com.aso114.project.bean.QuestionContextListBean;
import com.aso114.project.bean.questioncontentListBean;

import java.util.ArrayList;

/**
 * Created by asus on 2019/1/25.
 */

public class HelperBean {

    public static ArrayList<QuestionBaseBean> getBaseBean(QuestionBean qdata) {
        ArrayList<QuestionBaseBean> baseBean = new ArrayList<>();
        for (int i = 0; i < qdata.getQuestionBaseList().size(); i++) {
            for (int j = 0; j < qdata.getQuestionBaseList().get(i).getQuestionList().size();
                 j++) {
                QuestionBaseBean questionBaseBean = new QuestionBaseBean();

                questionBaseBean.setQuestionBaseId(qdata.getQuestionBaseList().get(i)
                        .getQuestionBasicId());
                questionBaseBean.setPaperId(qdata.getQuestionBaseList().get(i).getPaperId
                        ());
                questionBaseBean.setQuantity(qdata.getQuestionBaseList().get(i)
                        .getQuantity());
                questionBaseBean.setTitle(qdata.getQuestionBaseList().get(i).getTitle());
                questionBaseBean.setDescription(qdata.getQuestionBaseList().get(i)
                        .getDescription());
                questionBaseBean.setRealPaperId(qdata.getQuestionBaseList().get(i)
                        .getRealPaperId());
                questionBaseBean.setRealBaseId(qdata.getQuestionBaseList().get(i)
                        .getRealBaseId());
                questionBaseBean.setQuestionId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getQuestionId());
                questionBaseBean.setCateId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList
                                ().get(j).getCateId());
                questionBaseBean.setBaseId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList
                                ().get(j).getBaseId());
                questionBaseBean.setUserId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList
                                ().get(j).getUserId());
                questionBaseBean.setRealQuestionId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getRealQuestionId());
                questionBaseBean.setOrderNumber(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getOrderNumber());
                questionBaseBean.setRealPaperTitle(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getRealPaperTitle());
                questionBaseBean.setFormatContent(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getFormatContent());
                questionBaseBean.setFormatImages(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getFormatImages());
                questionBaseBean.setExamPaperType(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getExamPaperType());
                questionBaseBean.setQuestionScore(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getQuestionScore());
                questionBaseBean.setErrorScore(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getErrorScore());
                questionBaseBean.setErrorScoreType(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getErrorScoreType());
                questionBaseBean.setDeductionScore(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getDeductionScore());
                questionBaseBean.setDifficultyFactor(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getDifficultyFactor());
                questionBaseBean.setContextQuestionId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getContextQuestionId());
                questionBaseBean.setAnswerCount(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getAnswerCount());
                questionBaseBean.setAnswerErrorCount(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getAnswerErrorCount());
                questionBaseBean.setQuestionTypeId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getQuestionTypeId());
                questionBaseBean.setSpecialId(qdata.getQuestionBaseList().get(i)
                        .getQuestionList().get(j).getSpecialId());
                questionBaseBean.setCollect("1".equals(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getIsCollect()));
                if (qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionsAnswerInfo().getAnswerArray().toString().equals(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getUserAnswer().toString())) {
                    questionBaseBean.setChooseResult(true);
                } else {
                    questionBaseBean.setChooseResult(false);
                }

                QuestionBaseBean.questionStatisticsInfo questionStatisticsInfo = new QuestionBaseBean.questionStatisticsInfo();
                questionStatisticsInfo.setQuestionStatisticId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionStatisticsInfo().getQuestionStatisticId());
                questionStatisticsInfo.setQuestionId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionStatisticsInfo().getQuestionId());
                questionStatisticsInfo.setRightRatio(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionStatisticsInfo().getRightRatio());
                questionStatisticsInfo.setRightCount(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionStatisticsInfo().getRightCount());
                questionStatisticsInfo.setWrongRatio(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionStatisticsInfo().getWrongRatio());
                questionStatisticsInfo.setWrongCount(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionStatisticsInfo().getWrongCount());
                questionBaseBean.setQuestionStatisticsInfo(questionStatisticsInfo);

                QuestionBaseBean.QuestionsAnswerInfo questionsAnswerInfo = new QuestionBaseBean.QuestionsAnswerInfo();
                questionsAnswerInfo.setQuestionId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionsAnswerInfo().getQuestionId());
                questionsAnswerInfo.setAnswerArray(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionsAnswerInfo().getAnswerArray());
                questionsAnswerInfo.setFormatContent(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionsAnswerInfo().getFormatContent());
                questionsAnswerInfo.setFormatImages(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestionsAnswerInfo().getFormatImages());
                questionBaseBean.setQuestionsAnswerInfo(questionsAnswerInfo);

                QuestionBaseBean.userAnswerInfo userAnswerInfo = new QuestionBaseBean.userAnswerInfo();


                userAnswerInfo.setAnswerDuration(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getAnswerDuration());
                userAnswerInfo.setIsState(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getIsState());

                userAnswerInfo.setPaperId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getPaperId());
                userAnswerInfo.setRealQuestionId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getRealQuestionId());
                userAnswerInfo.setQuestionNumber(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getQuestionNumber());
                userAnswerInfo.setQuestionScore(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getQuestionScore());
                userAnswerInfo.setCateId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getCateId());
                userAnswerInfo.setUserAnswer(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getUserAnswer());


                userAnswerInfo.setUserAnswerId(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getUserAnswerInfo().getUserAnswerId());
                questionBaseBean.setUserAnswerInfo(userAnswerInfo);


                ArrayList<questioncontentListBean> questioncontentListBeans = new ArrayList<>();
                questioncontentListBeans.addAll(qdata.getQuestionBaseList().get(i).getQuestionList().get(j).getQuestioncontentList());
                questionBaseBean.setQuestioncontentList(questioncontentListBeans);

                if (questionBaseBean.getUserAnswerInfo().getUserAnswer().size()==0) {
                    questionBaseBean.setFinishAnswer(false);
                } else {
                    questionBaseBean.setFinishAnswer(true);
                    if (questionBaseBean.getQuestionsAnswerInfo().getAnswerArray().toString().equals(questionBaseBean.getUserAnswerInfo().getUserAnswer().toString())) {
                        questionBaseBean.setChooseResult(true);
                        for (int k = 0; k < questionBaseBean.getQuestioncontentList().size(); k++) {
                            if (questionBaseBean.getQuestioncontentList().get(k).getSelectKey().equals(questionBaseBean.getUserAnswerInfo().getUserAnswer().get(0))) {
                                questionBaseBean.setRightAnswer(k + 1);
                            }
                        }
                    } else {
                        questionBaseBean.setChooseResult(false);
                        for (int k = 0; k < questionBaseBean.getQuestioncontentList().size(); k++) {
                            if (questionBaseBean.getQuestioncontentList().get(k).getSelectKey().equals(questionBaseBean.getUserAnswerInfo().getUserAnswer().get(0))) {
                                questionBaseBean.setErrorAnswer(k + 1);
                            }
                            if (questionBaseBean.getQuestioncontentList().get(k).getSelectKey().equals(questionBaseBean.getQuestionsAnswerInfo().getAnswerArray().get(0))) {
                                questionBaseBean.setRightAnswer(k + 1);
                            }
                        }
                    }

                }
                ArrayList<QuestionContextListBean> questionContextListBean = new ArrayList<>();
                questionContextListBean.addAll(qdata.getQuestionsContextList());
                questionBaseBean.setQuestionsContextList(questionContextListBean);

                baseBean.add(questionBaseBean);
            }
        }
        return baseBean;
    }
}
